#pragma once
#include"rbTree.h"

template<class K, class V>
class Mymap
{
public:
	struct MapKeyOfT
	{
		const K& operator()(const pair<K,V>& kv)
		{
			return kv.first;
		}
	};
		typedef typename RBTree<K, pair<const K,V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::ConstIterator const_iterator;
		iterator begin()
		{
			return _m.Begin();
		}

		iterator end()
		{
			return _m.End();
		}
		const_iterator begin()const
		{
			return _m.Begin();
		}

		const_iterator end()const
		{
			return _m.End();
		}
		pair<iterator,bool>insert(const pair<K, V>& kv)
		{
			return _m.insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = insert(make_pair(key, V()));
			return ret.first->second;
		}

		iterator find(const pair<K,V>& kv)
		{
			return _m.Find(kv);
		}

private:
	RBTree<K, pair<const K,V>, MapKeyOfT> _m;
};